package com.kevin.executors;

import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;

public class Executor {
	static Logger logger = Logger.getLogger(Executor.class);
	public static void main(String[] args) {

		Map map = new ConcurrentHashMap();
		testScheduledThreadPool();
	}

	public static void testExecutorService() {
		ExecutorService newCachedThreadPool = Executors.newFixedThreadPool(10);
		for (int i = 0; i < 100; i++) {
			// logger.info("------begin------------");
			Future<String> result = newCachedThreadPool.submit(new Callable<String>() {
				@Override
				public String call() throws Exception {
					Thread.sleep(1000);
					logger.info("-----------------call--------------");
					return "11000000";
				}
			});
		}
	}

	public static void testScheduledThreadPool() {
		ScheduledExecutorService threadPool = Executors.newScheduledThreadPool(1);
		for (int i = 0; i < 1; i++) {
			// logger.info("------begin------------");
			Runnable task = new Runnable() {
				@Override
				public void run() {
					try {
						Thread.sleep(1);
					} catch (InterruptedException e) {
						logger.error(e.getMessage(), e);
					}
					logger.info("-----------------call--------------");
				}
			};
			threadPool.scheduleWithFixedDelay(task, 10l, 80l, TimeUnit.SECONDS);
		}
	}
}

